New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat #297 Support default values from rich contract data #349
Feat #297 Support default values from rich contract data #349
Conversation
✔️ Preview deployment is ready! 🔨 Explore the source changes: 5245054 😎 Browse the preview: https://bafybeiazxxbgkz6kern2suj5zoiqzoa6wp72pyswxwbz2yazevtvujxgze.ipfs.cf-ipfs.com |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeihifkqp7hm3cka773yp6ex6onwe4kxec6jfwig6mnhwxabzqlols4.ipfs.cf-ipfs.com |
✔️ Preview deployment is ready! 🔨 Explore the source changes: 3c6df13 😎 Browse the preview: https://bafybeigjndwkcqsosp6ksnzh2x2t67gtgwtlysbeczw5s2rifdvdbzu4ha.ipfs.cf-ipfs.com |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeie4hrunndder2q7y47lb2ykj4nhinxu3qxxmbodwod4bakcctydva.ipfs.cf-ipfs.com |
✔️ Preview deployment is ready! 🔨 Explore the source changes: 0308aef 😎 Browse the preview: https://bafybeigjndwkcqsosp6ksnzh2x2t67gtgwtlysbeczw5s2rifdvdbzu4ha.ipfs.cf-ipfs.com |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeigtv45hup6fegfqpz637y6vp5mcqiegsjqhs3gpmjmycjge2kuebm.ipfs.cf-ipfs.com |
Here's a video of the interactions. This causes this side-effects in:
If I understand the issue correctly, the locking logic (preventing a user to mistakenly modify a default value in a contract call) should be only applied while making a contract call, not in other places we use the same component. What's tricky about this is that currently I think we don't seem to have a mechanism to tell the component that it is inside a contract call, and that's the main challenge. |
|
||
const inputRegex = RegExp(`^\\d*(?:\\\\[.])?\\d*$`); // match escaped "." characters via in a non-capturing group | ||
|
||
export const NumericalInput: React.FC<InputProps<string>> = ({ | ||
value, | ||
onChange, | ||
placeholder, | ||
disabled = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the default behaviour for all NumericalInputs
to be locked (disabled).
The default should be disabled = false
since in most cases its expected the user inputs a value.
This might be an unexpected side-effect of the fact that all values are initialized as BigNumber.from(0)
t prevent errors.
Also it conflicts with the SetPermissions
behaviour since a user can now unlock the amount
field (originally locked and toggled to max).
import { FiUnlock, FiX } from 'react-icons/fi'; | ||
import { ClickableIcon } from './AddressInput'; | ||
|
||
export const IconRight = ({ | ||
disabled = true, | ||
value, | ||
onChange, | ||
setDisabled, | ||
type, | ||
}) => { | ||
const clearLabel = `clear ${type}`; | ||
|
||
if (!disabled && value) { | ||
return ( | ||
<ClickableIcon aria-label={clearLabel} onClick={() => onChange('')}> | ||
<FiX size={18} /> | ||
</ClickableIcon> | ||
); | ||
} else if (disabled) { | ||
return ( | ||
<ClickableIcon | ||
aria-label="enable" | ||
onClick={() => { | ||
setDisabled(false); | ||
console.log(disabled); | ||
}} | ||
> | ||
<FiUnlock size={18} /> | ||
</ClickableIcon> | ||
); | ||
} else return null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we toggle the unlock
button, we can't toggle it back on.
We have two competing icons: a lock and a clear (X) icon. Maybe if we show both the UI gets too crowded.
Just pointing this behaviour, I don't know what the end result should look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, yes, this is true. i don't think the idea was to lock the input after unlocking it but it's good you point it out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leave the behaviour as is right now and later consider how we would have a lock icon
const [disabledState, setDisabled] = useState(value ? disabled : false); | ||
const iconRightProps = { | ||
disabled: disabledState, | ||
value: value, | ||
onChange: onChange, | ||
setDisabled, | ||
type: 'address', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This locks the address field if it has value, like in the case of a user editing a function call permission.
…rom-rich-contract-data
|
||
const inputRegex = RegExp(`^\\d*(?:\\\\[.])?\\d*$`); // match escaped "." characters via in a non-capturing group | ||
|
||
export const NumericalInput: React.FC<InputProps<string>> = ({ | ||
value, | ||
onChange, | ||
placeholder, | ||
disabled = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think passing defaultValue here would be more flexible in future and would limit the locking to when it is explicitly needed
We found a bug where action index 2 on the contract for voting in dxvote is showing index 1 option when clicked. We have not had this behaviour before so would be great to fix here if it is simple. |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeidwarailizpqwpc2opbjcnkn4v6eipaxzspirvgcjplfejk7cfmpa.ipfs.cf-ipfs.com |
the branch is now mergeable, works locking the numerical or address input if it has a default value as requested. Still missing:
|
Nice! I've tested it and left some minor comments. I think it works as intended now 👍 Also, it'll have conflicts with PR #369 , since we're both changing About the pending tests: we should at least them to test the functionality of disabling the input if it has a default value and the unlock feature. |
I'm having the same issue as Filip. Created a transfer proposal, then created a voting proposal with the transfer proposal data (proposal ID and guild address), and I'm having an infinite loop on the action and can't see it in the proposal page. |
hey @Filipv95 can you try it out now please?
please try editing it as well because i'm having a problem but i think it's just my computer resources |
…rom-rich-contract-data
✔️ Preview deployment is ready! 🔨 Explore the source changes: 070a360 😎 Browse the preview at one of these gateways: |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeigyaealukmvhb2xp5mqo3cjw3emziququigkbe3o2dpxigkhdvffu.ipfs.cf-ipfs.com |
✔️ Preview deployment is ready! 🔨 Explore the source changes: dd4ef5b 😎 Browse the preview at one of these gateways: |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeid4fyfbbacqy3jicpgt34uldvbyxqls5xsuxcp2nch746hyblleuq.ipfs.cf-ipfs.com |
I can make a transfer proposal and a voting proposal for it 👍 LGTM |
Hey Tomas! Sorry for not looking at this PR earlier. Have some comments on this issue:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good ✅
src/components/ActionsModal/types.ts
Outdated
@@ -6,3 +6,8 @@ export interface ActionModalProps { | |||
onAddAction: (action: DecodedAction) => void; | |||
action?: DecodedAction; | |||
} | |||
|
|||
export interface SelectedFunction { | |||
functionName: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep it consistent. Should this be either functionName
and functionTitle
or name
and title
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️ Preview deployment is ready! 🔨 Explore the source changes: bd49d4e 😎 Browse the preview at one of these gateways: |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeiafimrb6p2ethd6y332tl4tmvc5cf4zrev5bx5jn2wzrrxfyrlf4u.ipfs.cf-ipfs.com |
✔️ Preview deployment is ready! 🔨 Explore the source changes: 7a9b775 😎 Browse the preview at one of these gateways: |
✔️ Storybook deployment is ready! 😎 Browse Storybook: https://bafybeihpumckuuc224j4gb3iklllk4cohmxlwfklhxdsl2kvcyrcc5jb5m.ipfs.cf-ipfs.com |
Changes look good 👍 |
const BYTES_32_LENGTH = 66; | ||
|
||
export function isBytes32(value: string) { | ||
return value && value.length === BYTES_32_LENGTH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could check also if it starts with 0x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought about this but i'm not sure if it would be correct because of examples like this one i saw on richContracts:
this ones are component text so it isn't exactly the same but i thought it could happen.
just to be clear, if there is a possibility of having on richContracts a component "string" and type "bytes32" that it doesn't start with 0x we shouldn't add this condition.
Let me know what to think, no problem on adding it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using the text input here because bytes 32 accepts numbers and text, so the bytes32 is just verification on the text. So we don't change anything about how we pass the data, just if we accept it. So since all bytes will have 0x at the start we can have 0x check as well as length (coming from the 32 number)
But we can merge this now and add it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work Tomas!
Description
Support default values from rich contract data. Disable input by default when receiving data. Adding unlock icon to enable.
22-09-26.Support.default.values.from.rich.contract.data.webm
Closes #297
Type of change
How Has This Been Tested?
Tested manually and added Tests
Checklist: